﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Configuration;
using System.Configuration;
using System.Configuration.Provider;

using System.Xml;
using System.Xml.Linq;
using MyDHServer.DataAccess;

namespace MyDHServer.Compontents.DataProvider
{
    public abstract  class BlogDataProvider:ProviderBase
    {
        private static BlogDataProvider _provider = null;
        private static CusProviderCollection<BlogDataProvider> _providers = null;
        private static object _lock = new object();

        static BlogDataProvider()
        {
            CreateDefaultCommonProvider();
        }
        public static BlogDataProvider Instance()
        {
            return _provider;
        }

        private static void CreateDefaultCommonProvider()
        {
            if (_provider ==null)
            {
                lock (_lock)
                {
                    if (_provider == null)
                    {
                        ProvidersConfigSection section = (ProvidersConfigSection)ConfigurationManager.GetSection("system.web/dataService");

                        //ProviderSettingsCollection Settings = (ProviderSettingsCollection)section["providers"];

                        _providers = new CusProviderCollection<BlogDataProvider>();

                        ProvidersHelper.InstantiateProviders(section.Providers, _providers, typeof(BlogDataProvider));

                        _provider = _providers["SqlBlogDataProvider"];
                    }
                }

            }
        }
        public abstract void AddBlog(DHBlog blog);
        public abstract void UpdateBlog(DHBlog blog);

        public abstract void DeleteBlog(int id);

        public abstract List<DHBlog> GetBlogs(); 

    }
}
